'''
Created on 2011-8-29

@author: Administrator
'''
import asyncore
import socket
import logging


class Server(asyncore.dispatcher):
    clientlist= []
    def __init__(self):
        asyncore.dispatcher.__init__(self)
        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socketlist = []

    def handle_accept(self):
        pair = self.accept()
        if pair is None:
            pass
        else:
            sock, addr = pair
            logging.info('Incoming connection from %s' % repr(addr))
            self.socketlist.append(sock)
    
    def get_connecter(self):
        sockets = self.socketlist
        self.socketlist = []
        return sockets
    
    def log_info(self, message, type='info'):
        logging.log(logging._levelNames[type.upper()], message)

